<?php

declare (strict_types=1);

namespace app\beautiful\controller\cashier;
use app\BaseController;
use app\beautiful\model\appointment\TechnicianModel;
use app\common\logic\DataLogic;
use app\common\model\ShopStoreModel;

class Technician extends BaseController{

    public function getSelectStoreList() {
        $where = [
            ['shop_id','=',$this->request->shopId],
            ['is_delete','=',0],
            ['enable','=',1],
        ];
        $store = new ShopStoreModel();
        $order=['is_main'=>'asc','add_time'=>'desc'];
        $field='*';
        $append=['add_time_format'];
        $return = DataLogic::getDataList($store,$where,$order,$field,$this->request->limit,$this->request->page,$append);
        return $this->success($return);
    }
    public function getTechnicianList()
    {
        $name=$this->request->param('name');
        $mobile=$this->request->param('mobile');
        $status=$this->request->param('status/d',1);
        $store_id = $this->request->param('store_id/d',0);
        $position_id = $this->request->param('position_id/d',0);
        $where=[
            ['shop_id','=',$this->request->shopId],
            ['status','=',$status],
            ['is_delete','=',0],

        ];
        if(!empty($store_id)){
            $where[] = ['store','=',$store_id];
        }
        if(!empty($name)) $where[]=['name','like','%'.$name.'%'];
        if(!empty($mobile)) $where[]=['mobile','=',$mobile];
        if(!empty($position_id)) $where[]=['position_id','=',$position_id];
        $technician_model= new TechnicianModel();
        $technician_model = $technician_model->withCount(['projects'=>function($query){
            $query->where([['is_delete','=',0]]);
        }]);
        $order=['add_time'=>'desc'];$field="*";$append=['add_time_format','tags_string','status_means'];
        $limit=$this->request->limit;$page=$this->request->page;
        $return = DataLogic::getDataList($technician_model,$where,$order,$field,$limit,$page,$append);
        return $this->success($return);

    }
}
